
package newpackage;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.effect.Lighting;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class CriaConsulta {
    final PacienteDAO pacienteDAO = new PacienteDAO();    

    public GridPane CriaGrid() {
        
        Label lbNome = new Label("Nome:");
        Label lbTelefone = new Label("Telefone:");
        Label lbMedico = new Label("Medico");
        Label lbEspecialidade = new Label("Especialidade");
        
        final TextField tbNome = new TextField();
        final TextField tbTelefone = new TextField();       
        final TextField tbMedico = new TextField();
        final TextField tbEspecialidade = new TextField();
        
        
        
        Button btMarcar = new Button("Marcar");
        btMarcar.setStyle("-fx-base: blue;");
        
        btMarcar.setOnAction(new EventHandler<ActionEvent>() {
            
            @Override
            public void handle(ActionEvent t) {
                Paciente p = new Paciente();
                p.setNome(tbNome.getText());
                p.setTelefone(tbTelefone.getText());
                pacienteDAO.save(p);
                
                tbNome.setText("");
                tbTelefone.setText("");
                final Stage stage = new Stage();
                javafx.scene.Group rootGroup = new javafx.scene.Group();
                Scene scene = new Scene(rootGroup, 350, 100);
                stage.setScene(scene);
                stage.centerOnScreen();
                stage.show();
                Text text = new Text("Cadastrado com Sucesso!");
                text.setFill(Color.DODGERBLUE);
                text.setEffect(new Lighting());
                text.setFont(Font.font(Font.getDefault().getFamily(), 30));
                Button ok = new Button();
                ok.setText("OK");
                ok.setMinWidth(80);
                VBox vBox3 = new VBox();
                vBox3.setSpacing(20);
                vBox3.getChildren().addAll(text, ok);
                vBox3.setAlignment(Pos.CENTER);
                BorderPane msg = new BorderPane();
                msg.setCenter(vBox3);
                rootGroup.getChildren().add(msg);
                ok.setOnAction(new EventHandler<ActionEvent>() {

                    @Override
                    public void handle(ActionEvent event) {
                        stage.hide();                        
                    }
                });
                
            }            
        });
        
        
        Button btLimpar = new Button("Limpar");
        btLimpar.setStyle("-fx-base: blue;");
        
        
        btLimpar.setOnAction(new EventHandler<ActionEvent>() {
            
            @Override
            public void handle(ActionEvent t) {
                tbNome.setText("");
                tbTelefone.setText("");
            }
        });
        
        GridPane gp = new GridPane();
        gp.setPadding(new Insets(10, 10, 10, 10));
        gp.setHgap(10);
        gp.setVgap(10);
        gp.add(lbNome, 0, 1);
        gp.add(lbTelefone, 0, 2);
        gp.add(lbMedico, 0, 3);
        gp.add(lbEspecialidade, 0, 4);
        gp.add(tbNome, 1, 1);
        gp.add(tbTelefone, 1, 2);
        gp.add(tbMedico, 1, 3);
        gp.add(tbEspecialidade, 1,4);
        gp.add(btMarcar, 0, 8);
        gp.add(btLimpar, 1, 8);
        
        
        return gp;
    }
}
